// 封装成函数
export function hyRequest(options) {
  return new Promise((resolve, reject) => {
    wx.request({
      ...options,
      success: (res) => {
        resolve(res.data)
      },
      fail: reject
    })
  })
}
// 封装成类-》实例

class HYRequest {
  constructor(baseURL) {
    this.baseURL = baseURL
  }
  request(options) {
    const {
      url
    } = options
    return new Promise((resolve, reject) => {
      wx.request({
        ...options,
        url: this.baseURL + url,
        success: (res) => {
          resolve(res.data)
        },
        // fail: reject
        fail: (err)=>{
          console.log('err',err);
        }
      })
    })
  }
  post(options) {
    return this.request({
      ...options,
      method: 'post'
    })
  }
  get(options) {
    return this.request({
      ...options,
      method: 'get'
    })

  }
}

export const hyREquestInstance = new HYRequest("http://codercba.com:1888/api")
export const hyloginREquestInstance = new HYRequest("http://123.207.32.32:3000")
// hyREquestInstance.request()
// hyREquestInstance.get()
// hyREquestInstance.post()